package me.gujun.ohos.taggroup.entry;

import me.gujun.ohos.taggroup.TagGroup;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

public class MainAbility extends Ability {
    private Text edit;
    private String[] tags = new String[]{};
    private int ddd = 0xff23;
    private TagGroup mDefaultTagGroup;
    private TagGroup mSmallTagGroup;
    private TagGroup mLargeTagGroup;
    private TagGroup mBeautyTagGroup;
    private TagGroup mBeautyInverseTagGroup;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        mDefaultTagGroup = (TagGroup) findComponentById(ResourceTable.Id_tag_group);
        mSmallTagGroup = (TagGroup) findComponentById(ResourceTable.Id_tag_group_small);
        mLargeTagGroup = (TagGroup) findComponentById(ResourceTable.Id_tag_group_large);
        mBeautyTagGroup = (TagGroup) findComponentById(ResourceTable.Id_tag_group_beauty);
        mBeautyInverseTagGroup = (TagGroup) findComponentById(ResourceTable.Id_tag_group_beauty_inverse);
        edit = (Text) findComponentById(ResourceTable.Id_edit);
        edit.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                gotoAbility(TagEditorAbility.class);
            }
        });
        mDefaultTagGroup.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {

            }
        });

    }
    private void gotoAbility(Class clazz) {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(this.getBundleName())
                .withAbilityName(clazz.getName())
                .build();
        intent.setParam("tags",tags);
        intent.setOperation(operation);
        startAbilityForResult(intent, ddd);
    }

    @Override
    protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) {
        super.onAbilityResult(requestCode, resultCode, resultData);
        if (requestCode == ddd) {
            tags = resultData.getStringArrayParam("tags");
            mDefaultTagGroup.setTags(tags);
            mSmallTagGroup.setTags(tags);
            mLargeTagGroup.setTags(tags);
            mBeautyTagGroup.setTags(tags);
            mBeautyInverseTagGroup.setTags(tags);
        }
    }
}
